package leetcode.秋招.奇安信;

import org.junit.Test;

import java.util.HashMap;

/**
 * @author ：zsy
 * @date ：Created 2021/9/23 15:48
 * @description：
 */


public class Solution {
    @Test
    public void Test() {
        System.out.println(DoPermute(3, 5));
    }
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param m int整型 初始给定的淘汰数字
     * @param n int整型 猴子数量
     * @return int整型
     */
    public int DoPermute (int m, int n) {
        // write code here
        Node header = new Node(1);
        Node pointer = header;
        for (int i = 2; i <= n; i++) {
            pointer.next = new Node(i);
            pointer = pointer.next;
        }
        pointer.next = header;
        pointer = header;
        while (pointer != pointer.next) {
            int i = 2;
            while (i < m) {
                pointer = pointer.next;
                i++;
            }
            pointer.next = pointer.next.next;
            pointer = pointer.next;
            m++;
        }
        return pointer.No;
    }
    class Node {
        int No;
        Node next;

        public Node(int no) {
            No = no;
        }
    }
}
